home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / copymove.swg / 0018_Copy file in EMS.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-08-27  |  2.5 KB  |  86 lines

  1. { MARK LEWIS }
  2.  
  3. PROGRAM EMSCopy;
  4.  
  5. USES
  6.   Objects;  {The Object unit is need to access TStream}
  7.  
  8. VAR
  9.   InFile,
  10.   OutFile   : PStream;       {Pointer to InPut/OutPut Files}
  11.   EmsStream : PStream;       {Pointer to EMS Memory Block}
  12.   InPos     : LongInt;       {Where are we in the Stream}
  13.  
  14. BEGIN
  15.   Writeln;
  16.   Writeln('                  EMSCopy v1.00');
  17.   Writeln;
  18.   Writeln('{ Mangled together from code in the FIDO PASCAL Echo }');
  19.   Writeln('{ Assembled by Mark Lewis                            }');
  20.   Writeln('{ Some ideas and code taken from examples by         }');
  21.   Writeln('{ DJ Murdoch and Todd Holmes                         }');
  22.   Writeln('{ Released in the Public Domain                      }');
  23.   Writeln;
  24.   If ParamCount < 2 Then
  25.   Begin
  26.     Writeln('Usage: EMSCopy <Source_File> <Destination_File>');
  27.     Halt(1);
  28.   End;
  29.  
  30.   Infile := New(PBufStream, init(paramstr(1), stOpenRead, 4096));
  31.   If (InFile^.Status <> stOK) Then
  32.   Begin
  33.     Writeln(#7, 'Error! Source File Not Found!');
  34.     InFile^.Reset;
  35.     Dispose(InFile, Done);
  36.     Halt(2);
  37.   End;
  38.  
  39.   Outfile := New(PBufStream, init(paramstr(2), stCreate, 4096));
  40.   If (OutFile^.Status <> stOK) Then
  41.   Begin
  42.     Writeln(#7,'Error! Destination File Creation Error!');
  43.     OutFile^.Reset;
  44.     Dispose(OutFile, Done);
  45.     Halt(3);
  46.   End;
  47.  
  48.   EmsStream := New(PEmsStream, Init (16000, InFile^.GetSize));
  49.   If (EmsStream^.Status <> stOK) Then
  50.   Begin
  51.     Writeln(#7, 'Error! EMS Allocation Error!');
  52.     Writeln('At Least One Page of EMS Required :(');
  53.     EmsStream^.Reset;
  54.     Dispose(EmsStream, Done);
  55.     Halt(4);
  56.   End;
  57.  
  58.   Writeln('InPut File Size : ', InFile^.Getsize : 10, ' Bytes');
  59.   InPos := EmsStream^.GetSize;
  60.   Repeat
  61.     Write('Filling EMS Buffer...     ');
  62.     EmsStream^.CopyFrom(InFile^, InFile^.GetSize - InPos);
  63.     if (EmsStream^.Status <> stOK) then
  64.       EmsStream^.Reset;
  65.  
  66.     InPos := InPos + EmsStream^.GetSize;
  67.     Write(EmsStream^.GetSize : 10, ' Bytes   ');
  68.     EmsStream^.Seek(0);
  69.     Write('Writing DOS File... ');
  70.     OutFile^.CopyFrom(EmsStream^, EmsStream^.GetSize);
  71.     Writeln(OutFile^.Getsize : 10, ' Bytes');
  72.     If (InFile^.Status <> stOK) Then
  73.       InFile^.Reset;
  74.     If (OutFile^.GetSize < InFile^.GetSize) Then
  75.     Begin
  76.       EmsStream^.Seek(0);
  77.       EmsStream^.Truncate;
  78.       InFile^.Seek(InPos);
  79.     End;
  80.   Until (OutFile^.GetSize = InFile^.GetSize);
  81.   Writeln('Done!');
  82.   DISPOSE(InFile, Done);
  83.   DISPOSE(OutFile, Done);
  84.   DISPOSE(EmsStream, Done);
  85. END.
  86.